Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

327
Visualizações
How to prevent "my own" javascript code to open a new window?

This one is hard...

I have this task to build a module for a big system made with PHP. The most important rule is that I can't touch the code of the core system, so I can't fix some of it's bugs.

The main service of my module is to create a custom document that is not edited by the system default editor, but by a custom form created by my module.

To prevent users from editing the custom document instead of filling the form, I can set the document to blocked at the time of creation.

But even with the document being blocked, the system opens its default editor in a new pop-up window, and then shows an incorrect error message that has nothing to do with the block, and it is messing with the users heads.

I could fix this in a minute by changing a few lines in the core code, but then I would loose my job. I also can't ask the owner of the system to fix the problem because it would take forever (the owner is from a public institution).

The system function goes like this:

  1. When user creates document, it passes execution to a function on each module, so these modules could have the possibility to react to the document creation;
  2. The module receives data about the document created and checks if its type is the custom document type, then block it if true;
  3. The module passes execution back to code system, which finishes creating document (so I can't use die() otherwise document isn't created at all);
  4. The system open an editor so user can put content in it.

So I came with an idea that my module could, after blocking the document, output a javascript tag with code that would prevent javascript code created by the core system from using the window.open() command, or at least hide this pop-up.

Is there a way to do it with javascript?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can overwrite the open if your code can run before the open occurs:

const myOpen = window.open;
let iwanttopen = false:
window.open = function() {
  if (iwanttoopen) return myOpen(...arguments); // here YOU decide
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda